<template>
  <div class="container">
    <ul class="step">
      <li class="step-li" :class="step == 0 ? 'active' : ''">
        <span>1</span>
        <p>填写主题信息</p>
      </li>
      <li class="step-li" :class="step == 1 ? 'active' : ''">
        <span>2</span>
        <p>加入相关档案</p>
      </li>
      <li class="step-li" :class="step == 2 ? 'active' : ''">
        <span>3</span>
        <p>确认已选信息</p>
      </li>
      <li class="step-li" :class="step == 3 ? 'active' : ''">
        <span>4</span>
        <p>创建完成</p>
      </li>
    </ul>
    <div class="step-info">
      <ul class="step-info-ul" v-show="step == 0">
        <li class="step-info-li">
          <span class="s1"> <i>*</i>名称</span>
          <el-input
            class="step-ipt"
            v-model="manageInfo.entityName"
            type="txt"
            placeholder="请填写主题名称"
          ></el-input>
          <span class=""></span>
        </li>
        <li class="step-info-li">
          <span class="s1"> <i>*</i>主题类型</span>
          <div>
            <el-select
              class="step-ipt"
              v-model="manageInfo.entityType"
              placeholder="请选择档案类型"
              @change="handleChange"
            >
              <el-option
                v-for="(item, index) in themeList"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <span class=""></span>
        </li>
        <li class="step-info-li">
          <span class="s1">主题标签</span>
          <div class="ipt-box">
            <el-input
              class="step-ipt"
              v-model="label"
              type="txt"
              placeholder="请填写主题标签"
            ></el-input>
            <div class="label-d" v-show="manageInfo.labelList.length">
              <span
                class="label-item"
                v-for="(item, index) in manageInfo.labelList"
                :key="index"
              >
                <i
                  @click="removeItem(index, 'labelList')"
                  class="el-icon-close"
                ></i>
                {{ item }}
              </span>
            </div>
          </div>
          <span class="again" @click="setLabel"
            ><i class="el-icon-plus"></i>继续填写</span
          >
        </li>
        <li class="step-info-li">
          <span class="s1">主题介绍</span>
          <div class="ipt-box">
            <el-input
              class="step-ipt"
              v-model="manageInfo.entityAbstract"
              type="textarea"
              rows="5"
              placeholder="请填写主题介绍"
            ></el-input>
          </div>
          <span></span>
        </li>
      </ul>
      <div class="step-info-tj" v-show="step == 1">
         <div class="search-box">
          <input
            v-model="search"
            class="search"
            type="text"
            placeholder="请输入人名或特征词"
          />
          <i class="el-icon-search" @click="getData(0)"></i>
        </div>
        <ul class="info-ul" v-loading="loading">
          <li class="info-item" v-for="(item, index) in checkList" :key="index">
            <el-checkbox class="el-chek" v-model="item.checked"></el-checkbox>
            <div class="info-box">
              <div class="info">
                <div class="name-time">
                  {{
                    type == 3
                      ? item.twitterName
                        ? item.twitterName
                        : item.entityName
                      : item.entityName
                  }}
                </div>
                <p class="label" v-if="type != 3">
                  <span
                    v-for="(items, indexs) in item.labelTypes"
                    :key="indexs"
                    >{{ items }}</span
                  >
                </p>
                <p class="info-tit ellipsis2">
                  {{ item.mentions ? item.mentions : item.abstractType }}
                </p>
              </div>
              <p class="all" v-if="type == 3">
                <span>
                  <i class="iconf icontwitter"></i>
                  推文总数：{{ item.twitterAmout }}
                </span>
                <span>
                  <i class="iconf iconwujiaoxing"></i>
                  关注：{{ item.twitterAttention }}
                </span>
                <span>
                  <i class="iconf iconxin"></i>
                  粉丝：{{ item.twitterFans }}
                </span>
              </p>
            </div>
          </li>
        </ul>
        <p class="more">
          <span @click="getMore">
            加载更多 <i class="jt el-icon-d-arrow-right"></i>
          </span>
        </p>
      </div>
      <div class="step-info-tj" v-show="step == 2">
        <ul class="info-ul">
          <li
            class="info-item"
            v-for="(item, index) in checkedList"
            :key="index"
          >
            <el-checkbox class="el-chek" v-model="item.checked"></el-checkbox>
            <div class="info-box">
              <div class="info">
                <div class="name-time">
                  {{
                    type == 3
                      ? item.twitterName
                        ? item.twitterName
                        : item.entityName
                      : item.entityName
                  }}
                </div>
                <p class="label" v-if="type != 3">
                  <span
                    v-for="(items, indexs) in item.labelTypes"
                    :key="indexs"
                    >{{ items }}</span
                  >
                </p>
                <p class="info-tit ellipsis2">
                  {{ item.mentions ? item.mentions : item.abstractType }}
                </p>
              </div>
              <p class="all" v-if="type == 3">
                <span>
                  <i class="iconf icontwitter"></i>
                  推文总数：{{ item.twitterAmout }}
                </span>
                <span>
                  <i class="iconf iconwujiaoxing"></i>
                  关注：{{ item.twitterAttention }}
                </span>
                <span>
                  <i class="iconf iconxin"></i>
                  粉丝：{{ item.twitterFans }}
                </span>
              </p>
            </div>
          </li>
        </ul>
        <p class="show-info">
          您已筛选出<span>{{ checkedList.length }}</span
          >个档案
        </p>
      </div>
      <div class="step-info-success" v-show="step == 3">
        <div class="suc-box" v-loading="loading">
          <div>
            <p class="tips"><b>主题库已创建</b></p>
            <p class="tips">{{ time }}秒钟后进入主题页面</p>
            <p>
              <el-button type="primary" @click="linkThemeDetail"
                >查看主题</el-button
              >
            </p>
          </div>
        </div>
      </div>
      <div class="step-info-btn" :class="step != 0 ? 'right' : ''">
        <el-button
          class="btn-up"
          size="small"
          @click="step--"
          v-show="step != 0 && step < 3"
          >返回上一步</el-button
        >
        <el-button
          type="primary"
          size="small"
          @click="setStep"
          v-show="step < 3"
          >{{ step == 0 ? "下一步" : "确认已选信息" }}</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { CreateThemeEntity } from "@/api/theme";
import { GetPersonRecord } from "@/api/personal";
import { GetOrganizationRecord } from "@/api/organization";
import { GetTwitterRecord } from "@/api/twitter";
import {
  tipErr,
  tipSuc,
  tipWarn,
  formatDate,
  funcChangeNumToCHN,
} from "@/utils/index";
export default {
  data() {
    return {
      loading: false,
      step: 0,
      search:'',
      label: "",
      label2: "",
      themeList: [
        {
          label: "人物档案主题",
          value: "THEME_PER",
        },
        {
          label: "机构档案主题",
          value: "THEME_ORG",
        },
        {
          label: "推特档案主题",
          value: "THEME_TWI",
        },
      ],
      entityId: "",
      manageInfo: {
        entityType: "",
        entityName: "",
        labelList: [],
        entityAbstract: "",
        entityIdList: [],
        link: true,
      },

      checkList: [],
      pageNum: 0,
      success: false,
      time: 5,
      timeout: null,
    };
  },
  computed: {
    checkedList() {
      let arr;
      arr = this.checkList.filter((item) => {
        return item.checked == true;
      });
      return arr;
    },
    type() {
      let Num;
      if (this.manageInfo.entityType == "THEME_PER") {
        Num = 1;
      } else if (this.manageInfo.entityType == "THEME_ORG") {
        Num = 2;
      } else if (this.manageInfo.entityType == "THEME_TWI") {
        Num = 3;
      }
      return Num;
    },
  },
  watch: {
    checkedList(nVal) {
      let arr = [];
      nVal.forEach((item) => {
        if (item.checked == true) {
          arr.push(item.entityId);
        }
      });
      this.manageInfo.entityIdList = [...arr];
    },
  },
  methods: {
    setLabel() {
      if (this.label.trim() == "") {
        tipWarn("请填写特征词~");
      } else {
        this.manageInfo.labelList.push(this.label);
        this.label = "";
      }
    },
    removeItem(index, key) {
      let newA = [...this[key]];
      this[key] = newA.filter((item, indexs) => {
        return index != indexs;
      });
    },
    setStep() {
      if (this.step == 0) {
        if (!this.manageInfo.entityType) {
          tipErr("请选择档案类型");
          return;
        }
        if (!this.manageInfo.entityName) {
          tipErr("请输入名称");
          return;
        }
      }
      this.step++;
      if (this.step == 3) {
        this._CreateThemeEntity();
      }
    },
    async _GetPersonRecord(index) {
      let params = {
        recordScope: 0,
        row: 10,
        start: index?index:this.pageNum * 10,
        type: "PERSON",
      };
      if(this.search != ''){
       params = Object.assign(params, {searchContent: this.search});
      }
      let { data, code, msg, total } = await GetPersonRecord(params);
      this.loading = false;
      if (code == 1) {
        this.checkList =index==0?[...data.entityBasicInfoList]: [...this.checkList, ...data.entityBasicInfoList];
        this.pageNum =index?1 : this.pageNum + 1;
      } else {
        tipErr(msg);
      }
    },
    async _GetOrganizationRecord(index) {
      let params = {
        recordScope: 0,
        row: 10,
        start: index?index:this.pageNum * 10,
        type: "ORGANIZATION",
      };
      if(this.search != ''){
       params = Object.assign(params, {searchContent: this.search});
      }
      let { data, code, msg, total } = await GetOrganizationRecord(params);
      this.loading = false;
      if (code == 1) {
        this.checkList = index==0?[...data.entityBasicInfoList]: [...this.checkList, ...data.entityBasicInfoList];
        this.pageNum =index?1 : this.pageNum + 1;
      } else {
        tipErr(msg);
      }
    },
    async _CreateThemeEntity() {
      this.loading= true
      let { data, code, msg } = await CreateThemeEntity({ ...this.manageInfo });
      this.loading = false
      if (code == 1) {
        tipSuc("创建成功");
        this.entityId = data;
        this.timeoutfu(data);
      } else {
        tipErr("创建失败");
      }
    },
    timeoutfu(data) {
      let me = this;
      me.timeout = setTimeout(() => {
        me.time--;
        if (me.time == 0) {
          clearTimeout(me.timeout);
          me.timeout = null;
          me.$router.push({
            name: "themesdetail",
            query: {
              entityId: data,
              name: me.manageInfo.entityName,
              abstractType: me.manageInfo.entityAbstract,
              entityType: me.manageInfo.entityType,
            },
          });
        } else {
          this.timeoutfu();
        }
      }, 1000);
    },
    linkThemeDetail() {
      clearTimeout(this.timeout);
      this.timeout = null;
      this.$router.push({
        name: "themesdetail",
        query: {
          entityId: this.entityId,
          name: this.manageInfo.entityName,
          abstractType: this.manageInfo.entityAbstract,
          entityType: this.manageInfo.entityType,
        },
      });
    },
    handleChange(value) {
      this.checkList = [];
      this.getData();
    },
    getMore() {
      if (this.loading) return;
      this.loading = true;
      this.getData();
    },
    getData(index) {
      this.loading = true;
      if (this.manageInfo.entityType == "THEME_PER") {
        this._GetPersonRecord(index);
      } else if (vathis.manageInfo.entityTypelue == "THEME_ORG") {
        this._GetOrganizationRecord(index);
      } 
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 1400px;
  min-height: 80vh;
  margin: 0 auto;
  padding-top: 40px;
  background: #1f2025;
  display: flex;
  flex-direction: column;
  align-items: center;
  .step {
    display: flex;
    &-li {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 14px;
      color: #8a8f99;
      line-height: 16px;
      margin: 0 50px;
      span {
        width: 26px;
        height: 26px;
        background: #262930;
        border-radius: 50%;
        font-size: 16px;
        color: #eee;
        text-align: center;
        line-height: 26px;
        margin-bottom: 10px;
        font-style: italic;
        box-sizing: border-box;
        padding-right: 3px;
      }
      &.active {
        color: #cc7029;
        span {
          background: #cc7029;
          box-shadow: 0px -1px 0px 0px #f59449;
          color: #fff;
        }
      }
    }
  }
}
.step-info {
  &-ul {
    display: table;
    border-collapse: separate;
    border-spacing: 0 15px;
    margin-top: 60px;
  }
  &-li {
    display: table-row;
    span,
    div {
      display: table-cell;
    }
    .s1 {
      width: 120px;
      padding-right: 14px;
      text-align: right;
      font-size: 14px;
      color: #b8becc;
      font-weight: 700;
      i {
        color: #cc7029;
        font-style: normal;
        margin-right: 4px;
      }
    }
    .again {
      padding-left: 40px;
      font-size: 14px;
      color: #cc7029;
       cursor:pointer;
      .el-icon-plus {
        font-size: 18px;
        vertical-align: middle;
        margin-top: -5px;
      }
    }
    .ipt-box {
      width: 400px;
      .tips {
        padding-left: 16px;
        font-size: 12px;
        color: #525966;
        line-height: 20px;
      }
      .step-ipt {
        margin-bottom: 10px;
      }
      .label-d {
        display: flex;
        flex-wrap: wrap;
        .label-item {
          height: 20px;
          padding: 0 5px;
          background: #262930;
          margin: 0 10px 10px 0;
          position: relative;
          font-size: 12px;
          color: #8a8f99;
          .el-icon-close {
            display: none;
            font-size: 14px;
            color: #cc7029;
            position: absolute;
            top: -4px;
            right: -4px;
            cursor: pointer;
          }
          &:hover {
            .el-icon-close {
              display: block;
            }
          }
        }
      }
    }
    .step-ipt /deep/ {
      display: block;
      width: 400px;
      background: #262930;
      box-shadow: 0px -1px 0px 0px #282c33;
      border-radius: 2px;
      border: none;
      .el-input__inner {
        border: none;
        &::-webkit-input-placeholder {
          color: #525966;
        }
      }
      .el-textarea__inner {
        border: none;
        color: #eee;
        &::-webkit-input-placeholder {
          color: #525966;
        }
      }
    }
  }
  &-btn {
    width: 100%;
    text-align: right;
    padding-right: 114px;
    box-sizing: border-box;
    &.right {
      padding-right: 30px;
    }
  }
  &-tj {
    width: 1400px;
    padding: 40px 30px;
    box-sizing: border-box;
    .tip {
      font-size: 14px;
      color: #b8becc;
      line-height: 16px;
      margin-bottom: 15px;
    }
    .tips {
      font-size: 12px;
      color: #737780;
      line-height: 16px;
      margin-bottom: 12px;
    }
    .info-ul {
      min-height: 200px;
      .more {
        text-align: right;
        padding-top: 0;
      }
    }
    .info-item {
      width: 100%;
      padding: 20px 30px;
      box-sizing: border-box;
      background: #262930;
      margin-bottom: 10px;
      display: flex;
      .el-chek {
        width: 16px;
        height: 16px;
        margin-right: 13px;
      }
      .name-time {
        width: 100%;
        justify-content: space-between;
        font-size: 18px;
        line-height: 20px;
        color: #fff;
        font-weight: bold;
        margin-bottom: 14px;
        position: relative;

        .btn-box /deep/ {
          position: absolute;
          top: -10px;
          right: 0;
          height: 34px;
          display: flex;
          .follow {
            display: block;
            width: 80px;
            height: 34px;
            text-align: center;
            line-height: 34px;
            box-sizing: border-box;
            border-radius: 2px;
            font-size: 14px;
            color: #cc7029;
            background: rgba(204, 112, 41, 0.1);
            margin-left: 20px;
            cursor: pointer;
            .el-icon-plus {
              color: #cc7029;
              font-weight: 700;
              margin-right: 5px;
            }
          }
        }
        .no {
          border: 0.5px solid #cc7029;
          background: transparent;
        }
      }
      .label {
        display: flex;
        overflow: hidden;
        span {
          height: 28px;
          line-height: 28px;
          padding: 0 8px;
          font-size: 12px;
          color: #828999;
          background: #2e323b;
          margin-right: 10px;
        }
        margin-bottom: 12px;
      }
      .info-tit {
        font-size: 14px;
        color: #b8becc;
        line-height: 24px;
      }
      .all {
        display: flex;
        span {
          margin-right: 56px;
          font-size: 14px;
          color: #8a8e99;
        }
      }
    }
    .item-ul {
      height: 172px;
      overflow: hidden;
      &.all {
        height: auto;
      }
    }
    .item-list {
      display: flex;
      margin-bottom: 20px;
      span {
        font-size: 14px;
        color: #cc7029;
        line-height: 22px;
        width: 100px;
      }
      .txt {
        font-size: 14px;
        color: #b8becc;
        line-height: 22px;
      }
    }
    .more {
      text-align: center;
      padding-top: 10px;
      .jt {
        font-size: 16px;
        margin-top: -2px;
        vertical-align: middle;
      }
    }
    .tab {
      display: flex;
      border-left: 1px solid rgba(204, 112, 41, 0.4);
      .tab-list {
        border-top: 1px solid rgba(204, 112, 41, 0.4);
        border-right: 1px solid rgba(204, 112, 41, 0.4);
        border-bottom: 1px solid rgba(204, 112, 41, 0.4);
        height: 40px;
        box-sizing: border-box;
        font-size: 14px;
        color: #b8becc;
        line-height: 38px;
        padding: 0 15px;
        cursor: pointer;
        span {
          font-size: 16px;
          color: #cc7029;
          font-weight: 600;
        }
        &.active {
          border-color: #cc7029;
          background: #cc7029;
          color: #fff;
          span {
            color: #fff;
          }
        }
      }
    }
    .show-info {
      text-align: right;
      font-size: 14px;
      color: #b8becc;
      line-height: 16px;
      padding: 10px 0 15px;
      span {
        font-size: 16px;
        color: #cc7029;
        font-weight: 600;
      }
    }
    .show-tips {
      text-align: right;
      font-size: 12px;
      color: #737780;
    }
  }
  &-success {
    margin: 189px auto 0;
    width: 600px;
    height: 400px;
    background: #24262b;
    border-radius: 20px;
    padding: 50px;
    box-sizing: border-box;
    .suc-box {
      width: 500px;
      height: 300px;
      background: rgba(255, 255, 255, 0);
      border: 1px dashed #363840;
      border-radius: 20px;
      text-align: center;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .iconf {
      width: 110px;
      height: 80px;
      background: #2b2d33;
      border-radius: 15px;
      line-height: 80px;
      text-align: center;
      font-size: 36px;
      color: #b8becc;
      margin: 87px 0 28px;
    }
    .tips {
      font-size: 14px;
      color: #b8becc;
      b {
        font-size: 16px;
        color: #b8becc;
      }
      line-height: 18px;
      margin-bottom: 18px;
      span {
        font-size: 16px;
        color: #cc7029;
        font-weight: 600;
        margin: 0 5px;
      }
    }
  }
}
.search-box /deep/ {
  padding:20px 0;
  display: flex;
  .search {
    width: 350px;
    height: 40px;
    box-sizing: border-box;
    border: 1px solid #3d434d;
    padding: 0 10px;
    background: transparent;
    color: #fff;
    &::-webkit-input-placeholder {
      color: #525966;
    }
  }
  .el-icon-search {
    width: 50px;
    height: 40px;
    background: #3d434d;
    font-size: 18px;
    color: #a1a7b3;
    text-align: center;
    line-height: 40px;
    cursor: pointer;
    &:hover {
      background: #cc7029;
      color: #fff;
    }
  }
}
</style>
